// components/score-record/score-record.js
const httpApi = require("../../http/request"); //后续可以改为你自己的域名接口地址

Component({
  /**
   * 组件的属性列表
   */
  properties: {},
  lifetimes: {
    attached() {
      this.getScoreList();
    },
  },
  /**
   * 组件的初始数据
   */
  data: {
    recordList: [],
    totalScore: 0,
    loadMore: false,
    queryParams: {
      user_id: wx.getStorageSync("userInfo").id,
      page: 1,
      limit: 6,
    },
  },
  /**
   * 组件的方法列表
   */
  methods: {
    getScoreList() {
      this.setData({
        queryParams: {
          ...this.data.queryParams,
          user_id: wx.getStorageSync("userInfo").id,
        }
      })
      httpApi
        .Post("/index/getScoreRecord", this.data.queryParams)
        .then((res) => {
          if (res.status) {
            return;
          }
          this.setData({
            recordList: [...this.data.recordList, ...res.data],
            totalScore: res.sorce,
            loadMore:
              res.data.length < this.data.queryParams.limit ? false : true,
          });
        });
    },
    loadMoreData() {
      this.data.queryParams.page++;
      this.setData({
        ["queryParams.page"]: this.data.queryParams.page,
      });
      this.getScoreList();
    },
    closeRecord() {
      this.triggerEvent("closeRecord", true);
    },
  },
});
